package com.extension.company.view.localcity;

import android.content.Context;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.extension.company.admin.R;
import com.extension.company.common.mvp.BaseFragment;
import com.extension.company.contract.localcity.LocalCityFragmentContract;
import com.extension.company.presenter.localcity.LocalCityFragmentPresenter;
import com.extension.company.view.adapter.GirdDropDownAdapter;
import com.extension.company.view.adapter.ListDropDownAdapter;
import com.extension.company.view.adapter.LocationAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.yyydjk.library.DropDownMenu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 作者:zwk
 * 联系方式：497981239@qq.com
 * 时间：on 2019/6/23 14:54
 * 功能：
 */
public class LocalCityFragment extends BaseFragment<LocalCityFragmentContract.View, LocalCityFragmentPresenter> implements LocalCityFragmentContract.View {
	//	@BindView(R.id.local_city_fragment_list)
	ListView localCityFragmentList;
	//	@BindView(R.id.local_city_fragment_refrsh)
	SmartRefreshLayout localCityFragmentRefrsh;
	@BindView(R.id.dropDownMenu)
	DropDownMenu mDropDownMenu;


	private LocationAdapter adapter;

	private Context context;

	private String citys[] = {"不限", "武汉", "北京", "上海", "成都", "广州", "深圳", "重庆", "天津", "西安", "南京", "杭州"};
	private String ages[] = {"不限", "18岁以下", "18-22岁", "23-26岁", "27-35岁", "35岁以上"};
	private String headers[] = {"智能排序", "附近"};
	private List<View> popupViews = new ArrayList<>();


	public static LocalCityFragment getInstance() {

		return new LocalCityFragment();
	}


	@Override
	public void onAttach(Context context) {
		super.onAttach(context);
		this.context = context;
	}

	@Override
	public LocalCityFragmentContract.View createView() {
		return this;
	}

	@Override
	public LocalCityFragmentPresenter createPresenter() {
		return new LocalCityFragmentPresenter();
	}

	@Override
	public void init() {

		View view = LayoutInflater.from(context).inflate(R.layout.local_city_fragment_list, null);
		localCityFragmentList = view.findViewById(R.id.local_city_fragment_list);
		localCityFragmentRefrsh = view.findViewById(R.id.local_city_fragment_refrsh);

		adapter = new LocationAdapter(context);
		localCityFragmentList.setAdapter(adapter);

		final ListView cityView = new ListView(context);
		GirdDropDownAdapter cityAdapter = new GirdDropDownAdapter(context, Arrays.asList(citys));
		cityView.setDividerHeight(0);
		cityView.setAdapter(cityAdapter);
		//init age menu
		final ListView ageView = new ListView(context);
		ageView.setDividerHeight(0);
		ListDropDownAdapter ageAdapter = new ListDropDownAdapter(context, Arrays.asList(ages));
		ageView.setAdapter(ageAdapter);

		popupViews.add(cityView);
		popupViews.add(ageView);

		TextView contentView = new TextView(context);
		contentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
		contentView.setText("内容显示区域");
		contentView.setGravity(Gravity.CENTER);
		contentView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);

		mDropDownMenu.setDropDownMenu(Arrays.asList(headers), popupViews, view);

	}

	@Override
	public int getMainLayout() {
		return R.layout.local_city_fragment;
	}

	@Override
	public void showLoading() {

	}

	@Override
	public void hideLoading() {

	}

	@Override
	public void onError(Throwable throwable) {

	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
	}
}
